package com.block.common.security.service.impl.reqData;

import cn.hutool.core.codec.Base64Decoder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.block.common.security.service.ReqDataTransferService;
import com.block.common.security.util.ApiUtil;
import com.block.common.service.LogFactory;
import com.block.common.util.LogFilterUtil;
import com.block.common.util.RSACoderUtil;
import com.block.db.entity.AppEncrypt;
import org.slf4j.Logger;

/**
 * 默认处理 不做任何加密处理
 * 
 *
 */
public class DefaultReqTransferService extends ReqDataTransferService {
	private static Logger logger= LogFactory.getAppReq();
	@Override
	public JSONObject transferReqData(AppEncrypt appEncrypt, JSONObject jsonObject, String methodName) throws Exception {
		String encTranData=jsonObject.getString("tranData");
		String ciphertext=jsonObject.getString("ciphertext");

		String randKey= new String(RSACoderUtil.decryptByPrivateKey(Base64Decoder.decode(ciphertext),appEncrypt.getSecretKey()));
		logger.info("传入的tranData{},ciphertext:{},解密后的ciphertext:{}",encTranData,ciphertext,randKey);

		String tranData= ApiUtil.decode(appEncrypt,encTranData,randKey);
		JSONObject logJson= JSON.parseObject(tranData);
		logger.info("解密后的tranData{}",JSON.toJSONString(logJson));

		return JSONObject.parseObject(tranData);
	}

}
